﻿<RibbonWindow  x:Class="HolterDatabase.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:HolterDatabase"
        xmlns:s="clr-namespace:System;assembly=mscorlib"
        xmlns:hdvm="clr-namespace:HolterDatabase.ViewModel"
        Icon="images/icon.ico"
        Title="Holter Database" Height="910" MinHeight="910" Width="900" MinWidth="900">

    <RibbonWindow.Resources>
        <local:DateTimeConverter x:Key="DateTimeConverter" />
        <local:ValidatedToBoolConverter x:Key="ValidatedToBoolConverter" />
        <local:InternalToColorConverter x:Key="InternalToColorConverter" />
        
        <!-- Styles -->
        <Style x:Key="PatientSetControlDefaultStyle">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <DataGrid x:Name="mainDataGrid" ItemsSource="{Binding DataView}" AutoGenerateColumns="False" FontSize="14" Background="White">
                            <DataGrid.RowHeaderStyle>
                                <Style TargetType="DataGridRowHeader">
                                    <Setter Property="Width" Value="20" />
                                </Style>
                            </DataGrid.RowHeaderStyle>
                            <DataGrid.ColumnHeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="FontSize" Value="16" />
                                    <Setter Property="FontWeight" Value="Bold" />
                                </Style>
                            </DataGrid.ColumnHeaderStyle>
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Nom" Binding="{Binding LastName}" Width="100"/>
                                <DataGridTextColumn Header="Prénom" Binding="{Binding FirstName}" Width="100" />
                                <DataGridTextColumn Header="Date de naissance" Binding="{Binding BirthDate, Converter={StaticResource DateTimeConverter}}" />
                                <DataGridTextColumn Header="Adresse" Binding="{Binding Adress}" Width="*" />
                                <DataGridTextColumn Header="Telephone" Binding="{Binding Phone}" Width="*" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HolterSetControlDefaultStyle">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <DataGrid x:Name="mainDataGrid" ItemsSource="{Binding DataView}" AutoGenerateColumns="False" FontSize="14" SelectionChanged="OnHolterListSelectionChanged" Background="White">
                            <DataGrid.RowHeaderStyle>
                                <Style TargetType="DataGridRowHeader">
                                    <Setter Property="Width" Value="20" />
                                </Style>
                            </DataGrid.RowHeaderStyle>
                            <DataGrid.ColumnHeaderStyle>
                                <Style TargetType="DataGridColumnHeader">
                                    <Setter Property="FontSize" Value="16" />
                                    <Setter Property="FontWeight" Value="Bold" />
                                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Column.(ToolTipService.ToolTip)}"/>
                                </Style>
                            </DataGrid.ColumnHeaderStyle>
                            <DataGrid.RowStyle>
                                <Style TargetType="DataGridRow">
                                    <Setter Property="Background" Value="{Binding Internal, Converter={StaticResource InternalToColorConverter}}" />
                                </Style>
                            </DataGrid.RowStyle>
                            <DataGrid.Columns>
                                <DataGridCheckBoxColumn Header="V" ToolTipService.ToolTip="Holter validé" Binding="{Binding Validated, Converter={StaticResource ValidatedToBoolConverter}}" />
                                <DataGridTextColumn Header="Nom" Binding="{Binding LastName}" Width="100" />
                                <DataGridTextColumn Header="Prénom" Binding="{Binding FirstName}" Width="100" />
                                <DataGridTextColumn Header="Date de pose" Binding="{Binding OutDate, Converter={StaticResource DateTimeConverter}}" />
                                <DataGridTextColumn Header="Date de retour" Binding="{Binding ReturnDate, Converter={StaticResource DateTimeConverter}}" />
                                <DataGridTextColumn Header="Date de lecture" Binding="{Binding PlayDate, Converter={StaticResource DateTimeConverter}}" />
                                <DataGridTextColumn Header="Numéro d'examen" Binding="{Binding ExamNumber}" />
                                <DataGridTextColumn Header="Correspondant" Binding="{Binding Doctor}" />
                                <!--<DataGridTextColumn Header="Date de naissance" Binding="{Binding BirthDate, Converter={StaticResource DateTimeConverter}}" />
                                <DataGridTextColumn Header="Adresse" Binding="{Binding Adress}" />
                                <DataGridTextColumn Header="Téléphone" Binding="{Binding Phone}" />
                                <DataGridTextColumn Header="Heure de pose" Binding="{Binding OutTime}" />
                                <DataGridTextColumn Header="Indication" Binding="{Binding Indication}" />
                                <DataGridTextColumn Header="Traitement" Binding="{Binding Treatment}" />-->
                            </DataGrid.Columns>
                        </DataGrid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="HolterEntryDefaultStyle">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="170" />
                                <ColumnDefinition Width="300" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="68" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="Auto"  />
                                <RowDefinition Height="*"  />
                            </Grid.RowDefinitions>

                            <Rectangle RadiusX="5" RadiusY="5" Grid.ColumnSpan="3" Grid.RowSpan="21" Fill="AliceBlue" />

                            <Label Grid.ColumnSpan="2" Grid.Row="0" Content="Fiche Holter" Margin="2" FontWeight="Bold" FontSize="25" VerticalAlignment="Center"/>
                            <Image Grid.Column="1" Grid.Row="0" Margin="5" Source="images/Patient_Male.png" Width="50" Height="50" HorizontalAlignment="Right" />
                            <Image Grid.Column="1" Grid.Row="0" Margin="5,5,50,5" Source="images/Patient_Female.png" Width="50" Height="50" HorizontalAlignment="Right" />

                            <Label Grid.Column="0" Grid.Row="1" Content="Nom" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2"  />

                            <Label Grid.Column="0" Grid.Row="2" Content="Prénom" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2"  />

                            <Label Grid.Column="0" Grid.Row="3" Content="Date de naissance" Margin="2" FontWeight="Bold" />
                            <DatePicker Grid.Column="1" Grid.Row="3" SelectedDate="{Binding BirthDate, Mode=TwoWay}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="4" Content="Adresse" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="4" Text="{Binding Adress, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" MinLines="3" AcceptsReturn="True"  />

                            <Label Grid.Column="0" Grid.Row="5" Content="Téléphone" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="5" Text="{Binding Phone, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" />

                            <Label Grid.Column="0" Grid.Row="6" Content="Date de pose" Margin="2" FontWeight="Bold" />
                            <DatePicker Grid.Column="1" Grid.Row="6" SelectedDate="{Binding OutDate, Mode=TwoWay}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="7" Content="Heure de pose" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="7" Text="{Binding OutTime, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="8" Content="Date de retour" Margin="2" FontWeight="Bold" />
                            <DatePicker Grid.Column="1" Grid.Row="8" SelectedDate="{Binding ReturnDate, Mode=TwoWay}" Margin="2" Background="White"  />
                            
                            <Label Grid.Column="0" Grid.Row="9" Content="Date de lecture" Margin="2" FontWeight="Bold" />
                            <DatePicker Grid.Column="1" Grid.Row="9" SelectedDate="{Binding PlayDate, Mode=TwoWay}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="10" Content="Indication" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="10" Text="{Binding Indication, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="11" Content="Traitement" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="11" Text="{Binding Treatment, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="12" Content="Correspondant" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="12" Text="{Binding Doctor, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White"  />

                            <Label Grid.Column="0" Grid.Row="13" Content="Commentaires" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="13" Text="{Binding Comment, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" MinLines="4" AcceptsReturn="True"  />

                            <Label Grid.Column="0" Grid.Row="14" Content="Conclusion" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="14" Text="{Binding Conclusion, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" MinLines="4" AcceptsReturn="True" />

                            <Label Grid.Column="0" Grid.Row="15" Content="Règlement" Margin="2" FontWeight="Bold" />
                            <CheckBox Grid.Column="1" Grid.Row="15" IsChecked="{Binding Payment}"  Margin="2" Background="White" VerticalAlignment="Center" />

                            <Label Grid.Column="0" Grid.Row="16" Content="Validé" Margin="2" FontWeight="Bold" />
                            <CheckBox Grid.Column="1" Grid.Row="16" IsChecked="{Binding Validated}"  Margin="2" Background="White"  VerticalAlignment="Center" />

                            <Label Grid.Column="0" Grid.Row="17" Content="Durée du holter (en jours)" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="17" Text="{Binding Duration, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" />

                            <Label Grid.Column="0" Grid.Row="18" Content="Numéro d'examen" Margin="2" FontWeight="Bold" />
                            <TextBox Grid.Column="1" Grid.Row="18" Text="{Binding ExamNumber, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Margin="2" Background="White" />

                            <Label Grid.Column="0" Grid.Row="19" Content="Holter interne ?" Margin="2" FontWeight="Bold" />
                            <CheckBox Grid.Column="1" Grid.Row="19" IsChecked="{Binding Internal}" Margin="2" Background="White" VerticalAlignment="Center" />

                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Data Templates -->
        <DataTemplate DataType="{x:Type hdvm:PatientSetViewModel}">
            <Control Style="{StaticResource PatientSetControlDefaultStyle}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type hdvm:HolterSetViewModel}">
            <Control Style="{StaticResource HolterSetControlDefaultStyle}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type hdvm:HolterEntryViewModel}">
            <Control Style="{StaticResource HolterEntryDefaultStyle}" />
        </DataTemplate>

    </RibbonWindow.Resources>

    <DockPanel>
        <Ribbon x:Name="ribbon" DockPanel.Dock="Top" FocusManager.IsFocusScope="False" PreviewMouseDown="OnRibbonMouseDown">
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu>
                    <RibbonApplicationMenuItem Header="A propros de Holter Database" ImageSource="images/icon.ico" />
                    <RibbonApplicationMenu.FooterPaneContent>
                        <Grid Margin="8">
                            <TextBlock>Copyright Sami Touil</TextBlock>
                        </Grid>
                    </RibbonApplicationMenu.FooterPaneContent>
                </RibbonApplicationMenu>

            </Ribbon.ApplicationMenu>

            <RibbonTab Header="Accueil">

                <RibbonGroup Header="Presse-papiers">
                    <RibbonSplitButton Command="ApplicationCommands.Paste" Margin="5,0,0,0" LargeImageSource="images/paste.png" Label="Coller" VerticalAlignment="Top" >
                        <RibbonMenuItem Header="Collage spécial"></RibbonMenuItem>
                        <RibbonMenuItem Header="Collage par défaut"></RibbonMenuItem>
                    </RibbonSplitButton>
                    <RibbonButton Label="Cut" Command="ApplicationCommands.Cut" SmallImageSource="images/cut.png" VerticalAlignment="Top" />
                    <RibbonButton Label="Copy" Command="ApplicationCommands.Copy" SmallImageSource="images/copy.png" VerticalAlignment="Top" />
                </RibbonGroup>

                <RibbonGroup Header="Fiches">
                    <RibbonButton Label="Nouvelle Fiche" LargeImageSource="images/Add.png" VerticalAlignment="Top" Click="OnAddHolterEntry"/>
                    <RibbonButton x:Name="exportPdfButton" Label="Fiche PDF" LargeImageSource="images/adobe.png" VerticalAlignment="Top" Click="OnExportPdfChecked" IsEnabled="False" />
                </RibbonGroup>

                <RibbonGroup Header="Gestion des holters">
                    <RibbonRadioButton Label="Liste des holters" LargeImageSource="images/holter.png" VerticalAlignment="Top" GroupName="pages" Checked="OnHolterListChecked" IsChecked="True" />
                    <RibbonRadioButton  x:Name="patientCardButton" Label="Fiche holter" LargeImageSource="images/Clipboard.png" VerticalAlignment="Top" GroupName="pages" Checked="OnPatientCardChecked" IsEnabled="False"/>
                    <RibbonRadioButton Label="Liste des patients" LargeImageSource="images/folder.png" VerticalAlignment="Top" GroupName="pages" Checked="OnPatientListChecked"/>
                </RibbonGroup>

                <RibbonGroup Header="Sauvegarde">
                    <RibbonButton Label="Sauvegarder" LargeImageSource="images/Save.png" VerticalAlignment="Top" Click="OnSave" />
                    <RibbonButton Label="Exporter" LargeImageSource="images/export.png" VerticalAlignment="Top" Click="OnExport" />
                    <RibbonButton Label="Importer" LargeImageSource="images/import.png" VerticalAlignment="Top" Click="OnImport" />
                </RibbonGroup>

                <RibbonGroup Header="Recherche">
                    <RibbonContentPresenter Margin="0">
                        <RibbonContentPresenter.Content>
                            <StackPanel Orientation="Horizontal" >
                                <RibbonTextBox x:Name="searchText" KeyDown="OnValidateSearch" TextBoxWidth="150" />
                                <RibbonButton SmallImageSource="images/Zoom.png" VerticalAlignment="Top" Click="OnSearch" />
                            </StackPanel>
                        </RibbonContentPresenter.Content>
                    </RibbonContentPresenter>
                </RibbonGroup>

            </RibbonTab>
        </Ribbon>

        <ContentControl x:Name="content" Content="{Binding ActiveViewModel}" DockPanel.Dock="Bottom"/>

    </DockPanel>

</RibbonWindow>
